/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-21
 * Time: 23:28
 */
//https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/
public class Test {
    public static int takeAttendance(int[] arr) {
        int size=arr.length;
        if(arr[0]!=0){
            return 0;
        }
        if(arr[size-1]==size-1){
            return size;
        }
        int p1=1,p2=arr.length-1;
        int p=(p1+p2)/2;
        while(p1<=p2){
            if(arr[p]==p+1&&arr[p-1]==p-1){
                return p;
            }
            if(arr[p]==p){
                p1=p+1;
            }
            else{
                p2=p-1;
            }
            p=(p1+p2)/2;
        }
        return p;
    }

    public static void main(String[] args) {
        int[] arr={0,1,2,3,4,6,7,8,9};
        System.out.println(takeAttendance(arr));
    }
}
